package emulator.hardware.nmos6502.operands;

import emulator.hardware.HwByte;
import emulator.hardware.HwWord;
import emulator.hardware.debug.BusWatchException;
import emulator.hardware.memory.UnmappedMemoryException;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.util.MemoryPtr;

public class IndirectX extends ByteOperand {

	HwByte zp_addr = new HwByte();
	
	@Override
	public void init(Cpu6502 cpu) throws UnmappedMemoryException, BusWatchException {
		super.init(cpu);
		int full_addr = cpu.fetchProgramByte();
		zp_addr.setNumber(full_addr);
		full_addr = (int) ((full_addr + cpu.getX().getNumber()) & 0xFF);
		setAddress(new HwWord(cpu.readWord(full_addr)));
	}

	@Override
	public int getByteCount() {
		return 1;
	}

	/* (non-Javadoc)
	 * @see emulator.hardware.nmos6502.operands.ByteOperand#getString()
	 */
	@Override
	public String getString() {
		return "($"+zp_addr+",X)";
	}

	@Override
	public int getExtraCycles() {
		return 4;
	}
}
